#include "os/queue.h"
#include "os/os.h"
#include "utils/circle_buffer.h"

typedef struct {
	c_buffer_t buffer;
	int16_t esize;
}queue_t;

void *queue_create(u16 queue_count, u16 esize){
	queue_t *queue = (queue_t *)os_alloc(queue_count * esize + sizeof(queue_t));
	if (queue == NULL) {
		return NULL;
	}
	queue->esize = esize;
	circle_buffer_init(&queue->buffer, (u8 *)(queue + 1), queue_count * esize);
	return queue;
}
bool queue_put(co_queue_t vqueue, void *data){
	queue_t *queue = (queue_t *)vqueue;
	if (circle_put_data(&queue->buffer, data, queue->esize) > 0) {
		return true;
	}
	return false;
}

bool queue_get(co_queue_t vqueue, void *data) {
	queue_t *queue = (queue_t *)vqueue;
	if (circle_get_data(&queue->buffer, data, queue->esize) > 0) {
		return true;
	}
	return false;
}


